//
//  BasicViewController.m
//  TeamInformatization
//
//  Created by bigger on 2019/3/31.
//  Copyright © 2019年 SPIC. All rights reserved.
//

#import "BasicViewController.h"

@interface BasicViewController ()

@end

@implementation BasicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = kCommonBGGaryColor;
    NSLog(@"修改一下嘛");
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}

#pragma mark - Private
- (BOOL)IsRoot{
    if ([self.navigationController.viewControllers count] > 1) {
        return NO;
    }
    return YES;
}

- (float)show_View_Width{
    
    if (_show_View_Width == 0.0f) {
        _show_View_Width = WIDTH(self.view);
    }
    
    return _show_View_Width;
}

- (float)show_View_Height{
    
    if (_show_View_Height == 0.0f) {
        BOOL navigationBarHidden = self.titleBar ? self.titleBar.hidden : YES ;
        BOOL tabBarHidden = self.tabBarController? (self.IsRoot?NO:YES) : YES;
        float tabBarHeight = kSafeAreaBottomHeight;
        
        if (!navigationBarHidden && !tabBarHidden) {
            //都不隐藏
            _show_View_Height = HEIGHT(self.view) - HEIGHT(self.titleBar) -tabBarHeight;
        }
        else if (!navigationBarHidden){
            //navaigationbar不隐藏
            self.show_View_Height = HEIGHT(self.view) -HEIGHT(self.titleBar)-kSafeAreaBottomHeight;
        }
        else if (!tabBarHidden){
            //tabbar不隐藏
            self.show_View_Height = HEIGHT(self.view)-tabBarHeight;
        }
        else{
            //都隐藏
            self.show_View_Height = HEIGHT(self.view) - kSafeAreaBottomHeight;
        }
    }
    return _show_View_Height;
}

- (void)setTitle:(NSString *)title{
    
    if (self.titleBar) {
        self.titleBar.title = title;
    }
}

#pragma mark - TitleBar

//默认只展示title
- (void)showTitleBarWithTitle:(NSString *)title{
    
    Base_NavigationBarStyle leftButtonStyle = Base_NavigationBar_None;
    if (!self.IsRoot) {
        leftButtonStyle = Base_NavigationBar_Back;
    }
    [self showTitleBarWithTitle:title leftButtonStyle:leftButtonStyle rightButtonStyle:Base_NavigationBar_None];
}

- (void)showTitleBarWithTitle:(NSString *)title leftButtonStyle:(Base_NavigationBarStyle)leftButtonStyle rightButtonStyle:(Base_NavigationBarStyle)rightButtonStyle{
    
    if (!self.titleBar) {
        _titleBar = [[Base_TitleBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f,CGRectGetWidth(self.view.bounds), kNavigationBarHeight)];
        _titleBar.hidden = NO;
        _titleBar.titleBardelegate = self;
        [self.view addSubview:_titleBar];
    }
    
    self.titleBar.title = title;
    self.titleBar.leftButtonStyle = leftButtonStyle;
    self.titleBar.rightButtonStyle = rightButtonStyle;
    [self.view bringSubviewToFront:self.titleBar];
    
}

- (void)showTitleBarLogoImageView{
    
    if (self.titleBar) {
        UIImage * image = [UIImage imageNamed:@""];
        self.titleBar.title = @"";
        self.titleBar.titleImage = image;
    }
}

- (void)appearTitleBar:(BOOL)animated{
    
    self.titleBar.hidden = NO;
    [UIView animateWithDuration:animated ? 0.3f : 0 animations:^{
        self.titleBar.frame = CGRectMake(0, 0, CGRectGetWidth(self.titleBar.bounds), CGRectGetHeight(self.titleBar.bounds));
    }];
    
}

- (void)disappearTitleBar:(BOOL)animated{
    
    [UIView animateWithDuration:animated ? 0.3f : 0 animations:^{
        self.titleBar.frame = CGRectMake(0, -CGRectGetHeight(self.titleBar.bounds), CGRectGetWidth(self.titleBar.bounds), CGRectGetHeight(self.titleBar.bounds));
    }];
    self.titleBar.hidden = YES;
    
}

@end
